<template>
  <div class="goods-tabs">
    <nav>
      <a href="javascript:;"
      @click="changeTab('Detail')"
      :class="{ active: currContent === 'Detail' }"
      >商品详情</a>
      <a href="javascript:;"
       @click="changeTab('Comment')"
       :class="{ active: currContent === 'Comment' }"
       >商品评价<span>600+</span></a>
    </nav>
    <!-- 这个位置显示对应的组件 GoodsDetail 或者 GoodsComment -->
      <!-- 这个位置显示对应的组件 GoodsDetail 或者 GoodsComment -->
    <!-- :is="变量" 说明：变量值是当前组件下注册的子组件的标签名 -->
    <!-- 需求： 只缓存Detail组件-->
    <keep-alive include="GoodsDetail">
      <component :is="currContent" />
    </keep-alive>
  </div>
</template>
<script>
import { ref } from 'vue'
import Detail from './goods-detail.vue'
import Comment from './goods-comment.vue'
export default {
  name: 'GoodsTabs',
  components: {
    Detail,
    Comment
  },
  setup () {
    const currContent = ref('Comment')
    const changeTab = (curr) => {
      currContent.value = curr
    }
    return { currContent, changeTab }
  }
}
</script>
<style scoped lang="less">
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>
